package com.thinkgem.jeesite.common.exception;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;

import com.thinkgem.jeesite.common.utils.StringUtils;

@Controller
public class ExpController {
	/** 基于@ExceptionHandler异常处理 */  
    @ExceptionHandler
    public String exp(HttpServletRequest req, Exception ex) {  
          
        req.setAttribute("ex", ex);  
          
        /*// 根据不同错误转向不同页面  
        if(ex instanceof BusinessException) {  
            return "error-business";  
        }else if(ex instanceof ParameterException) {  
            return "error-parameter";  
        } else {  
            return "error";  
        }  */
        ex.printStackTrace();
        String errMsg = ex.getMessage();
        if(StringUtils.isBlank(errMsg))
        {
        	errMsg = ex.toString();
        }
        
        if(errMsg.indexOf("ORA-") > -1 || errMsg.indexOf("mapper") > -1 || errMsg.indexOf("orcl") > -1 || errMsg.indexOf("MyBatis") > -1)
        {
        	errMsg = "";
        }
        
        if(StringUtils.isBlank(errMsg))
        {
        	errMsg = "发生内部错误，请与管理员联系。";
        }
        else
        {
        	errMsg += ", 发生内部错误，请与管理员联系。";
        }
        
        System.out.println(ex.getMessage());
        // req.setAttribute("errMsg", errMsg);
        // return "base/exception/500";
        return "error/500";
        //views/error/500.jsp
    }
}
